# filename:yangsy.py
# -*- coding: UTF-8 -*-

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
import time

url = 'https://test.rabbitpre.com/'
driver = webdriver.Chrome()
driver.get(url)
driver.maximize_window()

# 登录：
sign_btn = driver.find_element_by_xpath('//*[@id="g-j-signin-btn"]')
sign_btn.click()
login_sso = driver.find_element_by_id('sso')
driver.switch_to.frame(login_sso)
driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/span[2]')
time.sleep(2)
account = driver.find_element_by_css_selector('div.tab-container span[data-type="tuzhan"]')
account.click()
driver.find_element_by_css_selector('input[type="text"]').send_keys('xxx')
driver.find_element_by_css_selector('div.password.form-password input[placeholder="请输入密码"]').send_keys('xxx')
driver.find_element_by_css_selector('button[class="g-btn login-btn do-btn"]').click()
time.sleep(2)
# 创建作品：
driver.find_element_by_link_text('新建作品').click()
windows = driver.window_handles
driver.switch_to.window(windows[-1])
driver.execute_script('window.scrollBy(0,700)')
time.sleep(2)
driver.find_element_by_css_selector('div.create-icon').click()
time.sleep(2)
driver.find_element_by_css_selector('span[class="text"]').click()
time.sleep(5)

save = WebDriverWait(driver, 10, 0.5).until(lambda x:x.find_element_by_xpath('//*[@id="popup-setting-container"]/div[1]/ul[2]/li[1]/div/div/div[6]/div[4]/button[2]'))
save.click()
time.sleep(3)

driver.quit()